import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:xindong/common/xindong_app_info.dart';
import 'package:xindong/common/xindong_sezhi.dart';
import 'package:xindong/common/xindong_all.dart';
import 'package:xindong/common/xindong_methods.dart';
import 'package:xindong/manager/xindong_page_singleton.dart';
import 'package:xindong/manager/xindong_user_controller.dart';
import 'package:xindong/widgets/xindong_avatar.dart';
import 'package:xindong/widgets/xindong_biaoqian_view.dart';

class XinDongWoDeHeaderView extends StatelessWidget {
  const XinDongWoDeHeaderView({super.key});

  void _onTap() {
    final mineUser = XinDongUserController.to.userInfo;
    XinDongPageSingleton.instance.jumpToSpace(mineUser);
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: _onTap,
      child: Container(
        width: double.infinity,
        // color: DZColors.cellColor,
        padding: const EdgeInsets.only(top: 26, bottom: 10),
        child: GetBuilder<XinDongUserController>(builder: (controller) {
          return Row(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              const SizedBox(width: 16),
              XinDongAvatarBorder(controller.userInfo, avatarSize: 56, borderColor: DZColors.coverColor),
              const SizedBox(width: 10),
              Expanded(
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Container(
                      height: 26,
                      alignment: Alignment.bottomLeft,
                      child: Row(
                        children: [
                          Text(
                            controller.userInfo?.getName ?? "",
                            maxLines: 1,
                            overflow: TextOverflow.ellipsis,
                            style: TextStyle(
                              fontSize: 18,
                              height: 1.2,
                              color: controller.userInfo?.is_noble == 1 ? Colors.red : DZColors.titleColor,
                            ),
                          ),
                          const SizedBox(width: 2),
                          if (controller.userInfo != null) XinDongBiaoQianList(user: controller.userInfo!),
                        ],
                      ),
                    ),
                    GestureDetector(
                      onTap: () {
                        Clipboard.setData(ClipboardData(text: controller.loginId ?? ""));
                        showToast("已复制");
                      },
                      behavior: HitTestBehavior.opaque,
                      child: Container(
                        height: 26,
                        padding: const EdgeInsets.only(top: 5),
                        child: Text(
                          "${XinDongAppDeviceInfo.instance.showAppName}号：${controller.userInfo?.uid ?? ""}",
                          style: const TextStyle(color: DZColors.contentColor, fontSize: 12, height: 1.2),
                        ),
                      ),
                    ),
                  ],
                ),
              ),
              XinDongAll.instance.defaultIconNext,
              const SizedBox(width: 16),
            ],
          );
        }),
      ),
    );
  }
}
